#include "Tracing.h"

Tracing::Tracing()
{
	totalXpens = 0;
	//monthlyXpens = 0;
	//dailyXpens = 0;
	totalPayment = 0;
	//date = "";
}

/*void Tracing::printReport()
{
	cout << "Your total expense till now is " << fixed << setprecision(2) << totalXpens << endl;
	if (date != "") {
		char* daydate;
		int year, month, day ,i;
		year = atoi(date.substr(0,4).c_str())-1900;
	    month = atoi(date.substr(4,2).c_str())-1;
		day = atoi(date.substr(6,2).c_str());
		struct tm OldDay = {0,0,12,day,month,year};
		daydate = asctime( &OldDay );
		cout << "Your average monthly expense from ";
		for (i = 0; i < 11; i++) cout << daydate[i];
		cout << year+1900 << " till now is " << fixed << setprecision(2) << monthlyXpens << endl;
		cout << "And your daily expense is " << fixed << setprecision(2) << dailyXpens << endl;
	}
}
/*
void Tracing::update(XpensItem& thisItem)
{
	int month,day,year;
	int diffday, diffmonth;

	if ( date == "" || thisItem.getItemspec() -> getDate() < date)  
		 date = thisItem.getItemspec() -> getDate();
	time_t t = std::time(NULL);
	tm* tod = localtime(&t);
	time_t today = mktime(tod);
	year = atoi(date.substr(0,4).c_str())-1900;
	month = atoi(date.substr(4,2).c_str())-1;
	day = atoi(date.substr(6,2).c_str());
	struct tm OldDay = {0,0,12,day,month,year};
	time_t oldestDate = mktime(&OldDay);
	diffday = (int) difftime(today, oldestDate)/(24*3600);
	diffmonth = (tod -> tm_year - year) * 12 + (tod -> tm_mon - month) + 1;
//	cout << diffmonth <<endl;
	monthlyXpens = totalXpens/diffmonth;
	dailyXpens = totalXpens/(diffday + 1);
}*/
void Tracing::addTracing(Item& thisItem){

	if (thisItem.isExpense()) totalXpens += thisItem.getPrice();
	else totalPayment += thisItem.getPrice();
}

void Tracing::deleteTracing(Item& thisItem){
	if (thisItem.isExpense()) totalXpens = totalXpens - thisItem.getPrice();
	else totalPayment = totalPayment - thisItem.getprice();
//	cout << totalXpens <<endl;
//	update(thisItem);
}

/*double Tracing::getdailyXpens()
{
	return dailyXpens;
}

double Tracing::getmonthlyXpens()
{
	return monthlyXpens;
}
*/
double Tracing::gettotalXpens()
{
	return totalXpens;
}

double Tracing::gettotalPayment()
{
	return totalPayment;
}

void Tracing::initialize(double tp,double tx)
{
	totalXpens = tx;
	totalPayment = tp;
//	monthlyXpens = mx;
//	dailyXpens = dx;
//	date = today;
}
/*
string Tracing::getDate(){
	return date;
}*/